package com.zjitc.Redis;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/12 14:14
 * @description:
 */
public class JedisProxy implements InvocationHandler{

  private Object target;
  private JedisPool pool;

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
      return method.invoke(this.target,args);
    }finally {
      if (this.target instanceof Jedis){
        pool.returnResource((Jedis)target);
        System.out.println("release the jedis connection");
      }
    }
  }
}
